// http request 请求拦截器
axios.interceptors.request.use(config => {
    // 在发送请求之前做些什么
    let pathname = location.pathname;
    if (localStorage.getItem('token')) {
        if (pathname != '/' && pathname != '/pages/login.html') {
            config.headers.common['token'] = localStorage.getItem('token');
        }
    }
    return config;
}, error => {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// http response 响应拦截器
axios.interceptors.response.use(response => {
    if (response.data.message == '401') {
        location.href = "/pages/login.html";
    }
    return response;
}, error => {
    alert("请求失败，请稍后重试！");
    return Promise.reject(error);
});
